MySQL数据库转Elasticsearch
过程
安装logstash
vim ./logstash/config/mysql2es.conf
input { stdin { } jdbc { jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/database?serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true" jdbc_user => "root" jdbc_password => "root" jdbc_driver_library => "/Users/admin/Environment/Elasticsearch/logstash-7.13.4/config/mysql-connector-java-8.0.25.jar" jdbc_driver_class => "com.mysql.cj.jdbc.Driver" statement => "SELECT sid as id FROM tiku" } } output { elasticsearch { hosts => "127.0.0.1:9200" index => "index1" document_type =>"_doc" document_id => "%{id}" } stdout { codec => json_lines } }
./bin/logstash -f ../config/mysql2es.conf